<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>propertyreplacer.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">propertyreplacer.js</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    Helper class for creating stubs for testing.
  </div>
  

        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="closure_goog_testing_propertyreplacer.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
          </ol>
        </div>
</div>

<h2 class="g-first">File Location</h2>
  <div class="g-section g-tpl-20-80">
    <div class="g-unit g-first">
      <div class="g-c-cell code-label">testing/propertyreplacer.js</div>
    </div>
  </div>
<hr/>


  <h2>Classes</h2>
 <div class="fn-constructor">
        <a href="class_goog_testing_PropertyReplacer.html">
          goog.testing.PropertyReplacer</a><br/>
        <div class="class-details">Helper class for stubbing out variables and object properties for unit tests.
This class can change the value of some variables before running the test
cases, and to reset them in the tearDown phase.
See googletest.StubOutForTesting as an analogy in Python:
<a href="http://protobuf.googlecode.com/svn/trunk/python/stubout.py">http://protobuf.googlecode.com/svn/trunk/python/stubout.py</a>

Example usage:
<pre class="lang-js">var stubs = new goog.testing.PropertyReplacer();

function setUp() {
// Mock functions used in all test cases.
stubs.set(Math, &#39;random&#39;, function() {
return 4;  // Chosen by fair dice roll. Guaranteed to be random.
});
}

function tearDown() {
stubs.reset();
}

function testThreeDice() {
// Mock a constant used only in this test case.
stubs.set(goog.global, &#39;DICE_COUNT&#39;, 3);
assertEquals(12, rollAllDice());
}</pre>

Constraints on altered objects:
<ul>
<li>DOM subclasses aren&#39;t supported.
<li>The value of the objects&#39; constructor property must either be equal to
the real constructor or kept untouched. In the latter case the objects&#39;
toString() method musn&#39;t be overridden.
</li></li></ul></div>
 </div>
      
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>


  <h2>Global Functions</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.testing.PropertyReplacer.deleteKey_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.testing.PropertyReplacer.</span><span class="entryName">deleteKey_<span class="args">(<span class="arg">obj</span>,&nbsp;<span class="arg">key</span>)</span>
        </span>
      </div>


     <div class="entryOverview">
       Deletes a key from an object. Sets it to undefined or empty string if the
delete failed.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">obj</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span><span>&nbsp;|&nbsp;</span><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span></div>
        <div class="entryOverview">The object or function to delete a key from.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">key</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The key to delete.</div>
     </td>
   </tr>
  </table>
      </div>
   
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_testing_propertyreplacer.js.source.html#line131">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>






  <td>
    <a name="goog.testing.PropertyReplacer.hasKey_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.testing.PropertyReplacer.</span><span class="entryName">hasKey_<span class="args">(<span class="arg">obj</span>,&nbsp;<span class="arg">key</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span></div>
      </div>


     <div class="entryOverview">
       Tells if the given key exists in the object. Ignores inherited fields.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">obj</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span><span>&nbsp;|&nbsp;</span><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span></div>
        <div class="entryOverview">The JavaScript or native object or function whose key is to be checked.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">key</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The key to check.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span></div>&nbsp;
            Whether the object has the key as own key.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_testing_propertyreplacer.js.source.html#line92">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



  <h2>Global Properties</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.testing.PropertyReplacer.NO_SUCH_KEY_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.testing.PropertyReplacer.</span><span class="entryName">NO_SUCH_KEY_</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
     </div>


     <div class="entryOverview">
       Indicates that a key didn&#39;t exist before having been set by the set() method.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_testing_propertyreplacer.js.source.html#line81">Code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Directory testing</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">File Reference</h2>
            <div id="sideFileIndex" rootPath="closure/goog" current="testing/propertyreplacer.js"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
